﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using UniCT.LinkShareWpf.Interface;
using System.ComponentModel;
using LinkShareWpf.ViewModel;
using UniCT.LinkShareWpf.Model;

namespace LinkShareWpf
{
    /// <summary>
    /// Interaction logic for LocalResourcesControl.xaml
    /// </summary>
    public partial class LocalResourcesControl : UserControl
    {

        public LocalResourcesControl()
        {
            InitializeComponent();
            (DataContext as LocalResourcesViewModel).MessageBoxRequest += (sender,e) =>
                {
                    MessageBox.Show((e as LinkShareWpf.ViewModel.LocalResourcesViewModel.MessageParameterEventArgs).message);
                };
        }   
                

        private void DataGrid_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            
            
            // ItemsControl è un contenitore di Items => In questo caso è il DataGrid
            // ItemsControl, DependencyObject
            // ContainerFromElement : Returns the container that belongs to the specified ItemsControl that owns the given container element.
            DataGridRow row = ItemsControl.ContainerFromElement((DataGrid)sender,
                         e.OriginalSource as DependencyObject) as DataGridRow;
            if (row != null)
                (DataContext as LocalResourcesViewModel).ShowResource(dg1.ItemsSource as ObservableCollection<Resource>, dg1.CurrentItem as Resource);
        }

    }
}
